package gov.pbc.nn.core.job;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.job.model.JobDefinition;
import com.bstek.bdf2.job.service.IJobDataService;
import com.bstek.dorado.core.Configure;

@Component
public class CoreJobDataService implements IJobDataService,
		ApplicationContextAware {

	private ApplicationContext context;

	@Override
	public String getCompanyId() {
		return Configure.getString("bdf2.fixedCompanyId");
	}

	@Override
	public List<JobDefinition> filterJobs(List<JobDefinition> jobs) {
		List<JobDefinition> list = new ArrayList<JobDefinition>();
		for (JobDefinition jd : jobs) {
			String beanId = jd.getBeanId();
			if (this.context.containsBean(beanId)) {
				list.add(jd);
			}
		}
		return list;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.context = applicationContext;
	}

}
